module.exports = {
    currentPage: null,
    onLoad: function(e, t) {
        // wx.hideTabBar()
        e.setData({
            __platform: getApp().getPlatform()
        }), "undefined" != typeof my && "pages/login/login" != e.route && t && (e.options || (e.options = t), 
        wx.setStorageSync("last_page_options", t)), this.currentPage = e;
        o = this;
        if (e.options) {
            var a = 0;
            if (e.options.user_id) a = e.options.user_id; else if (e.options.scene) if (isNaN(e.options.scene)) {
                var i = decodeURIComponent(e.options.scene);
                i && (i = getApp().utils.scene_decode(i)) && i.uid && (a = i.uid);
            } else a = e.options.scene; else if (null !== getApp().query) {
                var n = getApp().query;
                getApp().query = null, a = n.uid;
            }
            a && wx.setStorageSync("parent_id", a);
        }
        if (void 0 === e.openWxapp && (e.openWxapp = o.openWxapp), void 0 === e.showToast && (e.showToast = function(e) {
            o.showToast(e);
        }), void 0 === e._formIdFormSubmit) {
            var o = this;
            e._formIdFormSubmit = function(e) {
                o.formIdFormSubmit(e);
            };
        }
        this.setUserInfoShow(),this.setShowBon(),getApp().setNavigationBarColor(), this.setPageNavbar(e), e.naveClick = function(t) {
            getApp().navigatorClick(t, e);
        }, this.setDeviceInfo(), this.setPageClasses(), this.setUserInfo(), void 0 === e.showLoadling && (e.showLoading = function(e) {
            o.showLoading(e);
        }), void 0 === e.hideLoading && (e.hideLoading = function(e) {
            o.hideLoading(e);
          }), this.setAlipayMpConfig(), this.setWxappImg(), this.setStoreSetting(), void 0 === e.setTimeList && (e.setTimeList = function(e) {
            return o.setTimeList(e);
        }), this.setBarTitle();

        void 0 === e.hiedden_get_info && (e.hiedden_get_info = function (ee) {
          o.hiedden_get_info(ee);
        }), void 0 === e.getUserInfo && (e.getUserInfo = function (ee) {
          o.getUserInfo(ee);
        }), void 0 === e.onChooseAvatar && (e.onChooseAvatar = function (ee) {
            o.onChooseAvatar(ee);
        }), void 0 === e.setUserNickname && (e.setUserNickname = function (ee) {
            o.setUserNickname(ee);
        }), void 0 === e.myLogin && (e.myLogin = function () {
          o.myLogin();
        }), void 0 === e.getPhoneNumber && (e.getPhoneNumber = function (ee) {
          o.getPhoneNumber(ee);
        }), void 0 === e.setUserInfoShowUser && (e.setUserInfoShowUser = function (ee) {
          o.setUserInfoShowUser(ee);
        }), void 0 === e.back_one && (e.back_one = function (ee) {
          o.back_one(ee);
        }), void 0 === e.showpicker && (e.showpicker = function (ee) {
          o.showpicker(ee);
        }), void 0 === e.showpicker_reduce && (e.showpicker_reduce = function (ee) {
          o.showpicker_reduce(ee);
        }), void 0 === e.getGoodsInfo && (e.getGoodsInfo = function (ee) {
          o.getGoodsInfo(ee);
        }), void 0 === e.goTop && (e.goTop = function (ee) {
          o.goTop(ee);
        }), void 0 === e.get_all_color && (e.get_all_color = function (ee) {
          o.get_all_color(ee);
        }), void 0 === e.numberBlur && (e.numberBlur = function (ee) {
          o.numberBlur(ee);
        }), void 0 === e.numberAdd && (e.numberAdd = function (ee) {
          o.numberAdd(ee);
        }), void 0 === e.numberSub && (e.numberSub = function (ee) {
          o.numberSub(ee);
        }), void 0 === e.navigatorClickBabber && (e.navigatorClickBabber = function (ee) {
          o.navigatorClickBabber(ee);
        }), void 0 === e.hideAttrPicker && (e.hideAttrPicker = function (ee) {
          o.hideAttrPicker(ee);
        }), void 0 === e.attrGoodsClick && (e.attrGoodsClick = function (ee) {
          o.attrGoodsClick(ee);
        }), void 0 === e.addToCart && (e.addToCart = function (ee) {
          o.addToCart(ee);
        }), void 0 === e.onShareTimeline && (e.onShareTimeline = function (ee) {
          o.onShareTimeline(ee);
        });

      if (!(this.currentPage.route.indexOf('pages/index/index') >= 0 ||
        this.currentPage.route.indexOf('pages/cat/cat') >= 0 ||
        this.currentPage.route.indexOf('pages/cart/cart') >= 0 ||
        this.currentPage.route.indexOf('pages/posts/index') >= 0 ||
        this.currentPage.route.indexOf('pages/user/user') >= 0)
      ) {
        void 0 === e.switchTab && (e.switchTab = function (ee) {
          o.switchTab(ee);
        }), void 0 === e.switchTo && (e.switchTo = function (ee) {
          o.switchTo(ee);
        });
      }
    },
    onReady: function(e) {
        this.currentPage = e;
    },
    onShow: function(e) {
        //wx.hideTabBar()
        this.currentPage = e, getApp().order_pay.init(e, getApp());
        this.show_navs();
        this.get_all_color()
    },
    isIphoneX: function (e) {
      var that = this.currentPage;
      wx.getSystemInfo({
        success: function (res) {
          if ((res.model.indexOf("X") >= 0 || res.model.indexOf("iPhone11") >= 0 ) && res.model.indexOf('iPhone') >= 0) {
            that.setData({
              isIphoneX: true
            })
          }
        }
      })
    },
    onHide: function(e) {
        this.currentPage = e;
    },
    onUnload: function(e) {
        this.currentPage = e;
        wx.hideLoading()
    },
    showToast: function(e) {
        var t = this.currentPage, a = e.duration || 2500, i = e.title || "", n = (e.success, 
        e.fail, e.complete || null);
        t._toast_timer && clearTimeout(t._toast_timer), t.setData({
            _toast: {
                title: i
            }
        }), t._toast_timer = setTimeout(function() {
            var e = t.data._toast;
            e.hide = !0, t.setData({
                _toast: e
            }), "function" == typeof n && n();
        }, a);
    },
    formIdFormSubmit: function(e) {},
    setDeviceInfo: function() {
        var e = this.currentPage, t = [ {
            id: "device_iphone_5",
            model: "iPhone 5"
        }, {
            id: "device_iphone_x",
            model: "iPhone X"
        } ], a = wx.getSystemInfoSync();
        if (a.model) {
            a.model.indexOf("iPhone X") >= 0 && (a.model = "iPhone X");
            for (var i in t) t[i].model == a.model && e.setData({
                __device: t[i].id
            });
        }
    },
    setPageNavbar: function(e) {
        function t(t) {
            var a = !1, i = e.route || e.__route__ || null;
            for (var n in t.navs) t.navs[n].url === "/" + i ? (t.navs[n].active = !0, a = !0) : t.navs[n].active = !1;
            a && e.setData({
                _navbar: t
            });
        }
        var a = this, i = wx.getStorageSync("_navbar");
        i && t(i);
        var n = !1;
        for (var o in this.navbarPages) if (e.route == this.navbarPages[o]) {
            n = !0;
            break;
        }
        n && getApp().request({
            url: getApp().api.default.navbar,
            success: function(e) {
                0 == e.code && (t(e.data), wx.setStorageSync("_navbar", e.data), a.setPageClasses());
            }
        });
    },
    navbarPages: [ "pages/index/index", "pages/cat/cat", "pages/cart/cart", "pages/user/user","pages/posts/index", "pages/list/list", "pages/search/search", "pages/topic-list/topic-list", "pages/video/video-list", "pages/miaosha/miaosha", "pages/shop/shop", "pages/pt/index/index", "pages/book/index/index", "pages/share/index", "pages/quick-purchase/index/index", "mch/m/myshop/myshop", "mch/shop-list/shop-list", "pages/integral-mall/index/index", "pages/integral-mall/register/index", "pages/article-detail/article-detail", "pages/article-list/article-list" ],
    setPageClasses: function() {
        var e = this.currentPage, t = e.data.__device;
        e.data._navbar && e.data._navbar.navs && e.data._navbar.navs.length > 0 && (t += " show_navbar"), 
        t && e.setData({
            __page_classes: t
        });
    },
    setUserInfo: function() {
        var e = this.currentPage, t = wx.getStorageSync("user_info");
        t && e.setData({
            __user_info: t
        });
    },
    showLoading: function(e) {
        this.currentPage.setData({
            _loading: !0
        });
    },
    hideLoading: function(e) {
        this.currentPage.setData({
            _loading: !1
        });
    },
    setWxappImg: function(e) {
        var t = this.currentPage, a = wx.getStorageSync("wxapp_img");
        if (!a) {
          setTimeout(function () {
            a = wx.getStorageSync("wxapp_img");
            t.setData({
              __wxapp_img: a
            });
          },3000)
        }else {
          a && t.setData({
            __wxapp_img: a
          });
        }
    },
    setStoreSetting: function (e) {
      var t = this.currentPage, a = wx.getStorageSync("store");
      if (a) {
        t.setData({
          store_setting: a,
          store: a
        })
      }else {
        setTimeout(() => {
          a = wx.getStorageSync("store");
          t.setData({
            store_setting: a,
            store: a
          })
        }, 700);
      }
    },
    navigatorClickBabber: function(t) {
      var e = t.type == 'navigatorClickBabber' ? t.detail.currentTarget.dataset.url : t.currentTarget.dataset.url;
      var ee = function(t) {
        var a = /([^&=]+)=([\w\W]*?)(&|$|#)/g,
          e = /^[^\?]+\?([\w\W]+)$/.exec(t),
          i = {};
        if (e && e[1])
          for (var o, r = e[1]; null != (o = a.exec(r));) i[o[1]] = o[2];
        return i;
      }(e)
      var open_type = t.type == 'navigatorClickBabber' ? t.detail.currentTarget.dataset.open_type : t.currentTarget.dataset.open_type;
      if (open_type == 'wxapp') {
        var extraData = function(t) {
          var a = /([^&=]+)=([\w\W]*?)(&|$|#)/g,
            e = /^[^\?]+\?([\w\W]+)$/.exec(t),
            i = {};
          if (e && e[1])
            for (var o, r = e[1]; null != (o = a.exec(r));) i[o[1]] = o[2];
          return i;
        }(decodeURIComponent(ee.path))
        wx.navigateToMiniProgram({
          appId: ee.appId,
          path:decodeURIComponent(ee.path),
          extraData:extraData,
          fail: function () {
            
          }
        })
        return ;
      }
      // babber 链接
      var babber_url = [{
          "pagePath": "pages/index/index"
        },
        {
          "pagePath": "pages/cat/cat"
        },
        {
          "pagePath": "pages/cart/cart"
        },
        {
          "pagePath": "pages/user/user"
        },
        {
          "pagePath": "pages/posts/index"
        }
      ];
      var is_babber = 0;
      for (var i = 0; i < babber_url.length; i++) {
        if (e.indexOf(babber_url[i].pagePath) != -1) {
          if (ee.cat_id != '') {
            getApp().globalData.tab_cat_id = ee.cat_id;
            is_babber = 1;
          } else {
            is_babber = 1;
          }
  
        }
      }
      if (is_babber) {
        wx.switchTab({
          url: e
        })
      } else {
        wx.navigateTo({
          url: e　　 // 页面 A
        })
      }
  
      return false;
    },
    setTimeList: function(e) {
        function t(e) {
            return e <= 0 && (e = 0), e < 10 ? "0" + e : e;
        }
        var a = "00", i = "00", n = "00", o = 0;
        return e >= 86400 && (o = parseInt(e / 86400), e %= 86400), e < 86400 && (n = parseInt(e / 3600), 
        e %= 3600), e < 3600 && (i = parseInt(e / 60), e %= 60), e < 60 && (a = e), {
            day: o,
            hour: t(n),
            minute: t(i),
            second: t(a)
        };
    },
    setBarTitle: function(e) {
        var t = this.currentPage.route, a = wx.getStorageSync("wx_bar_title");
        for (var i in a) a[i].url === t && wx.setNavigationBarTitle({
            title: a[i].title
        });
    },
    setAlipayMpConfig: function() {return false;
        var e = this.currentPage, t = wx.getStorageSync("alipay_mp_config");
        t ? e.setData({
            __alipay_mp_config: t
        }) : getApp().request({
            url: getApp().api.default.store,
            success: function(a) {
                0 == a.code && (t = a.data.alipay_mp_config, wx.setStorageSync("alipay_mp_config", t), 
                e.setData({
                    __alipay_mp_config: t
                }));
            }
        });
    },
    openWxapp: function(e) {
        if (console.log("openWxapp---\x3e", e.currentTarget.dataset), e.currentTarget.dataset.url) {
            var t = e.currentTarget.dataset.url;
            (t = function(e) {
                var t = /([^&=]+)=([\w\W]*?)(&|$|#)/g, a = /^[^\?]+\?([\w\W]+)$/.exec(e), i = {};
                if (a && a[1]) for (var n, o = a[1]; null != (n = t.exec(o)); ) i[n[1]] = n[2];
                return i;
            }(t)).path = t.path ? decodeURIComponent(t.path) : "", wx.navigateToMiniProgram({
                appId: t.appId,
                path: t.path,
                complete: function(e) {}
            });
        } else {
            if (!e.currentTarget.dataset.appId || !e.currentTarget.dataset.path) return;
            wx.navigateToMiniProgram({
                appId: e.currentTarget.dataset.appId,
                path: e.currentTarget.dataset.path,
                complete: function(e) {}
            });
        }
    },
    setUserInfoShow: function () {
      var user_info = wx.getStorageSync("user_info");
      if (user_info && user_info.id > 0) {
        return false;
      }
      if (
        this.currentPage.route.indexOf('pages/integral-mall/register/index') >= 0 ||
        this.currentPage.route.indexOf('pages/new-order-submit/new-order-submit') >= 0 ||
        this.currentPage.route.indexOf('miaosha/miaosha') >= 0 ||
        this.currentPage.route.indexOf('pages/share/index') >= 0 ||
        this.currentPage.route.indexOf('pages/book/submit/submit') >= 0 ||
        this.currentPage.route.indexOf('bargain/list/list') >= 0 ||
        this.currentPage.route.indexOf('pages/ghs-apply/ghs-apply') >= 0 ||
        this.currentPage.route.indexOf('pages/tz-apply/tz-apply') >= 0 ||
        this.currentPage.route.indexOf('pages/commander/index') >= 0 ||
        this.currentPage.route.indexOf('pages/book/submit/submit') >= 0 ||
        this.currentPage.route.indexOf('bargain/activity/activity') >= 0 || 
        this.currentPage.route.indexOf('pages/posts-add/index') >= 0 ||
        this.currentPage.route.indexOf('pages/pt/order-submit/order-submit') >= 0 ||
        this.currentPage.route.indexOf('pages/coupon-list/coupon-list') >= 0 ||
        this.currentPage.route.indexOf('pages/pt/group/details') >= 0 ||
        //this.currentPage.route.indexOf('bargain/goods/goods') >= 0 ||
        this.currentPage.route.indexOf('pages/fxhb/open/open') >= 0 ||
        this.currentPage.route.indexOf('bargain/activity/activity') >= 0 ||
        this.currentPage.route.indexOf('bargain/order-list/order-list') >= 0 ||
        this.currentPage.route.indexOf('mch/shop/shop') >= 0 ||
        this.currentPage.route.indexOf('mch/shop-list/shop-list') >= 0 ||
        this.currentPage.route.indexOf('pt/order-submit/order-submit') >= 0 ||
        this.currentPage.route.indexOf('pages/fxhb/open/open') >= 0 ||
        this.currentPage.route.indexOf('pages/share/index') >= 0 ||
        this.currentPage.route.indexOf('pond/pond/pond') >= 0 ||
        this.currentPage.route.indexOf('miaosha/order-submit/order-submit') >= 0 ||
        this.currentPage.route.indexOf('pt/group/details') >= 0 ||
        this.currentPage.route.indexOf('pages/fxhb/detail/detail') >= 0 ||
        this.currentPage.route.indexOf('pages/commander/index') >= 0 ||
        this.currentPage.route.indexOf('pages/posts-self/index') >= 0 ||
        this.currentPage.route.indexOf('distributor/apply/index') >= 0 ||
        this.currentPage.route.indexOf('distributor/index/index') >= 0 ||
        this.currentPage.route.indexOf('distributor/user/index') >= 0 ||
        this.currentPage.route.indexOf('distributor/cash/index') >= 0 ||
        this.currentPage.route.indexOf('distributor/mch-order/index') >= 0 ||
        this.currentPage.route.indexOf('mch/apply/apply') >= 0 ||
        this.currentPage.route.indexOf('mch/m/myshop/myshop') >= 0 ||
        this.currentPage.route.indexOf('pages/bangding/bangding') >= 0) {
        if (this.currentPage.data.hedden_ != 1) {
          this.currentPage.setData({
            user_info_show: !0
          });
        }
      }

    },
    onShareTimeline: function () {
      var url = this.currentPage.route;
      var options  = wx.getStorageSync('last_page_options');
      return {
        title: '',
        query: options
      }
    },
  setShowBon: function () {
    if (
      this.currentPage.route.indexOf('pages/index/index') >= 0) {
      this.currentPage.setData({
        show_bon: !0
      });
    }
  },
  getUserInfo: function (e) {
    var t = this;
    var that = this.currentPage
    if (!that.data.avatarUrl || !that.data.nickname) {
        return wx.showToast({
            title: '请输入用户名或头像',
            icon: 'none'
        })
    } else {
        t.userLogin(e)
    }
  },
  userLogin: function (e) {
    var t = this;
    var scene = '';
    wx.getStorage({
      key: 'parent_id',
      success(res) {
        scene = { user_id: res.data }
      },
      fail() {
        wx.getStorage({
          key: 'scene',
          success(res) {
            scene = res.data
          }
        })
      }
    })
    wx.login({
      success: function (n) {
        var o = n.code;
        wx.getStorage({
          key: 'address_info',
          success: function (res) {
            t.unionLogin({
              code: o,
              parent_id: scene.user_id ? scene.user_id : 0,
              shop_id: res.data.shop_id ? res.data.shop_id : 0
            });
          },
          fail: function (res) {
            t.unionLogin({
              code: o,
              parent_id: scene.user_id ? scene.user_id : 0,
              shop_id: 0
            });
          }
        })
      },
      fail: function (e) { }
    });
  },
  myLogin: function (n) {
    var e = this;
    "undefined" != typeof my && my.getAuthCode({
      scopes: "auth_user",
      success: function (t) {
        if (e.is_login()) {
          var r = wx.getStorageSync("address_info");
          e.unionLogin({
            code: t.authCode,
            shop_id: r.shop_id
          });
        }
      }
    });
  },
  unionLogin: function (t) {
    var that = this;
   
    var thats = this.currentPage
    if (!thats.data.avatarUrl || !thats.data.nickname) {
        return wx.showToast({
            title: '请输入用户名或头像',
            icon: 'none'
        })
    } else {
        t.avatar = thats.data.avatarUrl
        t.nickname = thats.data.nickname
    }
    wx.showLoading({
      title: "正在登录",
      mask: !0
    }), getApp().request({
      url: getApp().api.passport.login,
      method: "POST",
      data: t,
      success: function (e) {
        if (0 == e.code) {
          // 更新社区信息
          that.is_login(e.data.p_shop_id)
          wx.setStorageSync("access_token", e.data.access_token), wx.setStorageSync("user_info", e.data);
          var t = that.currentPage;
          t && t.route || wx.switchTab({
            url: "/pages/index/index"
          });
          var n = 0;
          (n = t.options && t.options.user_id ? t.options.user_id : t.options && t.options.scene ? t.options.scene : wx.getStorageSync("parent_id")) && 0 != n && getApp().bindParent({
            parent_id: n
          });
          if (t.route.indexOf('pages/user/user') >= 0) {
            getCurrentPages()[getCurrentPages().length - 1].onShow()
          }
          that.back_one(t);
        } else wx.showModal({
          title: "提示",
          content: e.msg,
          showCancel: !1
        });

      },
      complete: function () {
        wx.hideLoading();
      }
    });
  },
  onChooseAvatar(e3) {
    var avatarUrl = e3.detail.avatarUrl
    var that = this.currentPage
    // 临时图片上传到服务器
    wx.showLoading({
      title: '上传中',
    })
    wx.uploadFile({
        url: getApp().api.default.upload_image,
        name: "image",
        formData: {},
        filePath: avatarUrl,
        complete: function (t) {
            wx.hideLoading()
          if (t.data) {
            var s = JSON.parse(t.data);
            if (s.code == 0) {
                that.setData({
                    avatarUrl: s.data.url
                })
            }
          }
        }
      });
  },
  setUserNickname(e) {
    console.log(e, 'eee')
    var nickname = e.detail.value
    var that = this.currentPage
    that.setData({
        nickname: nickname
    })
  },
  getBackOne: function () {
    var that = this;
    var t = getCurrentPages();
    if (t.length) {
      var o = t[t.length - 1];
      if (o && "pages/login/login" != o.route) if ("undefined" != typeof my) {
        var g = wx.getStorageSync("last_page_options"), n = {
          route: t[t.length - 1].route,
          options: g || {}
        };
        wx.setStorageSync("login_pre_page", n);
      } else wx.setStorageSync("login_pre_page", o);
    }
  },
  setUserInfoShowFalse: function () {
    this.currentPage.setData({
      user_info_show: !1
    });
  },
  getPhoneNumber: function (o) {
    var n = this.currentPage, a = this;
    "getPhoneNumber:fail user deny" == o.detail.errMsg ? getApp().core.showModal({
      title: "提示",
      showCancel: !1,
      content: "未授权"
    }) : (getApp().core.showLoading({
      title: "授权中"
    }), getApp().core.login({
      success: function (e) {
        if (e.code) {
          var t = e.code;
          getApp().request({
            url: getApp().api.user.user_binding,
            method: "POST",
            data: {
              iv: o.detail.iv,
              encryptedData: o.detail.encryptedData,
              code: t
            },
            success: function (e) {
              if (0 == e.code) {
                var t = n.data.__user_info;
                t.binding = e.data.dataObj, getApp().setUser(t), n.setData({
                  PhoneNumber: e.data.dataObj,
                  __user_info: t,
                  binding: !0,
                  binding_num: e.data.dataObj
                }), a.loadRoute();
              } else getApp().core.showToast({
                title: "授权失败,请重试"
              });
            },
            complete: function (e) {
              getApp().core.hideLoading();
            }
          });
        } else getApp().core.showToast({
          title: "获取用户登录态失败！" + e.errMsg
        });
      }
    }));
  },
  setUserInfoShowUser: function () {
    this.currentPage.setData({
      user_info_show: !0
    });
  },
  hiedden_get_info: function () {
    this.currentPage.setData({
      user_info_show: false,
      hedden_: 1
    });
    if (this.currentPage.route == 'pages/goods/goods') {
      return false;
    } else if (this.currentPage.route == 'pages/pt/order-submit/order-submit' || this.currentPage.route == 'bargain/activity/activity' || this.currentPage.route == 'bargain/goods/goods'  || this.currentPage.route == 'pages/user/user') {
      wx.switchTab({
        url: '/pages/index/index'
      });
    } else {
      getCurrentPages().length >= 2 && wx.navigateBack({//返回
        delta: 1
      });
    }
  },
  tabbar_to: function (t) {
    var that = this;
    var istabber = 0;
    var tabbar_list= [
      'pages/index/index',
      'pages/cat/cat',
      'pages/posts/index',
      'pages/cart/cart',
      'pages/user/user'
    ]
    for (var i = 0; i < tabbar_list.length; i++) {
      if (t.route == tabbar_list[i]) {
        istabber = 1;
      }
    }
    if (istabber == 1) {
      wx.switchTab({
        url: "/" + t.route + "?" + getApp().utils.objectToUrlParams(t.options)
      });
    } else {
      wx.redirectTo({
        url: "/" + t.route + "?" + getApp().utils.objectToUrlParams(t.options)
      });
    }
  },
  back_one: function () {
    var e = this.currentPage;
    "pages/index/index" == e.route || wx.redirectTo({
      url: "/" + e.route + "?" + getApp().helper.objectToUrlParams(e.options)
    }), this.setUserInfoShowFalse();
  },
  unicode: function (str) {
    var unid = '\\u';
    for (var i = 0; i < str.length; i++) {
      if (str.charCodeAt(i).toString(10) < 16) {
        unid += '000' + str.charCodeAt(i).toString(16);
      } else if (str.charCodeAt(i).toString(10) < 256) {
        unid += '00' + str.charCodeAt(i).toString(16);
      } else if (str.charCodeAt(i).toString(10) < 4096) {
        unid += '0' + str.charCodeAt(i).toString(16);
      } else {
        unid += str.charCodeAt(i).toString(16);
      }
      if (i < str.length - 1) {
        unid += '\\u'
      }

    }
    return unid;
  },
  is_login: function (tt) {
    var that = this.currentPage;
    var _this = this
    if (tt > 0) {
      this.setShopInfo(tt)
    } else {
      wx.getLocation({
        success: function (res) {
          that.setData({
            longitude: res.longitude,
            latitude: res.latitude
          });
          _this.setShopInfo(0, res.longitude, res.latitude)
        },
        fail: function (res) {
          getApp().getauth({
            content: "需要获取您的地理位置授权，请到小程序设置中打开授权",
            success: function(e) {
                e && (e.authSetting["scope.userLocation"] ? t.dingwei() : wx.showToast({
                    title: "您取消了授权",
                    image: "/images/icon-warning.png"
                }));
            }
          });
        },
        complete: function () {
          return true;
        }
      });
    }
    return true;
  },
  setShopInfo (tt, longitude, latitude) {
    getApp().request({
      url: getApp().api.default.index_position,
      data: {
        tz_id: tt,
        longitude: longitude,
        latitude: latitude,
      },
      method: "POST",
      success: function (t) {
        wx.setStorage({
          key: "address_info",
          data: {
            nickname: t.nickname,
            name: t.name,
            address: t.address,
            distance: t.distance,
            logo: t.logo,
            shop_id: t.shop_id
          }
        })
      },
    })
  },
  // 选择属性
  showpicker: function (goods) {
    if (!wx.getStorageSync('user_info') || wx.getStorageSync('user_info').length == 0) {
      this.currentPage.setData({
        user_info_show: !0
      });
      return false;
    }
    var goods_id = goods.type !=  "showpicker"? goods.currentTarget.dataset.id : goods.detail.id;
    this.currentPage.setData({
      goods_cart_index: goods.currentTarget.dataset.index
    })
    this.getGoodsInfo(goods_id);
  },
  showpicker_reduce: function (tt) {
    var i = this;
    var goods_index = tt.currentTarget.dataset.index;
    var goods_id = tt.currentTarget.dataset.id;

    getApp().request({
      url: getApp().api.default.cart_reduce,
      data: {
        goods_id: goods_id,
      },
      success: function (t) {
        if (wx.hideLoading(), 0 == t.code) {

        } else {
          wx.showToast({
            title: t.msg,
            icon: "none",
            duration: 1500
          })
        }
      }
    })
  },

  getGoodsInfo: function (goods_id) {
    var th = this.currentPage;
    var that = this;
    if (th.data.quick) {
      var r = th.data.carGoods;
      if (r) {
        for (var e = r.length, s = 0, d = 0; d < e; d++) r[d].goods_id == th.data.id && (s += parseInt(r[d].num));
        th.setData({
          goods_num: s
        });
      }
    }
    getApp().request({
      url: getApp().api.default.goods,
      data: {
        id: goods_id
      },
      success: function (t) {
        if (0 == t.code) {
          if (t.data.attr_group_list[0].attr_list.length == 1
             && t.data.attr_group_list[0].attr_list[0].attr_name == "默认") {
            // attr_group_list: t.data.attr_group_list
            t.data.attr_group_list[0].attr_list[0].checked = true;
            th.setData({
              goods_info: t.data,
              goods_num: t.data.shop_count> 0 ? t.data.shop_count : 1,
              attr_group_list: t.data.attr_group_list
            })
            that.addToCart();
            return true;
          }
          th.setData({
            goods_num: t.data.shop_count> 0 ? t.data.shop_count : 1,
            show_attr_picker: true
          });
          var o = t.data.detail;

          th.setData({
            goods_info: t.data,
            old_user: t.data.old_user,
            attr_group_list: t.data.attr_group_list
          })
        }
        1 == t.code && wx.showModal({
          title: "提示",
          content: t.msg,
          showCancel: !1,
          success: function (t) {
            t.confirm && wx.switchTab({
              url: "/pages/index/index"
            });
          }
        });
      }
    });
  },

  numberSub: function() {
    var that = this.currentPage;
    var goods_num = that.data.goods_num;
    var goods = that.data.goods_info ? that.data.goods_info : that.data.goods
    if (goods_num > 1) {
      goods.shop_count > 0 ? goods_num-=goods.shop_count : goods_num--
    }
    if (goods_num<1) {
      return false;
    }
    
    var minusStatus = goods_num <= 1 || (goods.shop_count>0&&goods_num <= goods.shop_count) ? 'disabled' : 'normal';
    that.setData({
      goods_num: goods_num,
      minusStatus: minusStatus
    });
  },
  numberAdd: function() {
    var that = this.currentPage;
    var goods_num = that.data.goods_num;
    var goods = that.data.goods_info ? that.data.goods_info : that.data.goods
    goods.shop_count > 0 ? goods_num+=goods.shop_count : goods_num++
    var minusStatus = goods_num < 1 ? 'disabled' : 'normal';
    that.setData({
      goods_num: goods_num,
      minusStatus: minusStatus
    });
  },
  numberBlur: function(e) {
    var that = this.currentPage;
    var goods_num = e.type !=  "numberBlur"? e.detail.value : e.detail.value;
    that.setData({
      goods_num: goods_num
    });
  },
  hideAttrPicker: function() {
    var that = this.currentPage;
    that.setData({
      show_attr_picker: false
    });
  },

   // 加入购物车
   addToCart: function() {
    this.submit('ADD_CART')
  },


  submit: function(a) {
    var i = this.currentPage;
    var that = this;
    if (i.data.miaosha_data && i.data.miaosha_data.rest_num > 0 && i.data.form.number > i.data.miaosha_data.rest_num) return wx.showToast({
      title: "商品库存不足，请选择其它规格或数量",
      image: "/images/icon-warning.png"
    }), !0;
    if (i.data.goods_num > i.data.goods_info.num) return wx.showToast({
      title: "商品库存不足，请选择其它规格或数量",
      image: "/images/icon-warning.png"
    }), !0;
    var r = i.data.attr_group_list,
      e = [];
    for (var s in r) {
      var d = !1;
      for (var n in r[s].attr_list)
        if (r[s].attr_list[n].checked) {
          d = {
            attr_id: r[s].attr_list[n].attr_id,
            attr_name: r[s].attr_list[n].attr_name
          };
          break;
        }
      if (!d) return wx.showToast({
        title: "请选择" + r[s].attr_group_name,
        image: "/images/icon-warning.png"
      }), !0;
      e.push({
        attr_group_id: r[s].attr_group_id,
        attr_group_name: r[s].attr_group_name,
        attr_id: d.attr_id,
        attr_name: d.attr_name
      });
    }
    var add_cat_num = i.data.goods_info.shop_count > 0 ? i.data.goods_info.shop_count : i.data.goods_num
    if ("ADD_CART" == a && (wx.showLoading({
        title: "正在提交",
        mask: !0
      }), getApp().request({
        url: getApp().api.cart.add_cart,
        method: "POST",
        data: {
          goods_id: i.data.goods_info.id,
          attr: JSON.stringify(e),
          num: add_cat_num
        },
        success: function(t) {
          wx.hideLoading(), wx.showToast({
            title: t.msg,
            duration: 1500
          }), i.setData({
            show_attr_picker: !1
          });
          that.cart_num()
        },
        fail:function(res){
          wx.hideLoading()
        },
        complete:function(res){
          // wx.hideLoading()
        }
        
      })), "BUY_NOW" == a) {
      i.setData({
        show_attr_picker: !1
      });
      var c = [];
      c.push({
        goods_id: i.data.id,
        num: i.data.form.number,
        attr: e
      });
      var u = i.data.goods,
        _ = 0;
      null != u.mch && (_ = u.mch.id);
      var g = [];
      g.push({
        mch_id: _,
        goods_list: c
      }), wx.redirectTo({
        url: "/pages/new-order-submit/new-order-submit?mch_list=" + JSON.stringify(g)
      });
    }
  },

  attrGoodsClick: function(a) {
    var i = this.currentPage,
      r = a.type !=  "attrGoodsClick" ? a.target.dataset.groupId : a.detail.groupId,
      e = a.type !=  "attrGoodsClick" ? a.target.dataset.id : a.detail.id,
      s = i.data.attr_group_list;
    for (var d in s)
      if (s[d].attr_group_id == r)
        for (var n in s[d].attr_list) s[d].attr_list[n].attr_id == e ? s[d].attr_list[n].checked = !0 : s[d].attr_list[n].checked = !1;
    i.setData({
      attr_group_list: s
    });
    var c = [],
      u = !0;
    for (var d in s) {
      var _ = !1;
      for (var n in s[d].attr_list)
        if (s[d].attr_list[n].checked) {
          c.push(s[d].attr_list[n].attr_id), _ = !0;
          break;
        }
      if (!_) {
        u = !1;
        break;
      }
    }
    u && (wx.showLoading({
      title: "正在加载",
      mask: !0
    }), getApp().request({
      url: getApp().api.default.goods_attr_info,
      data: {
        goods_id: i.data.goods_info.id,
        attr_list: JSON.stringify(c)
      },
      success: function(t) {
        if (wx.hideLoading(), 0 == t.code) {
          var a = i.data.goods_info; 
          a.price = t.data.price, a.num = t.data.num, a.attr_pic = t.data.pic, i.setData({
            goods_info: a
            // goods :a
          });
        }
      }
    }));
  },
  // 获取购物车数量
  cart_num: function () {
    var that = this.currentPage;
    wx.getStorage({
      key: 'user_info',
      success: function(res) {
        getApp().request({
          url: getApp().api.cart.list,
          success: function (t) {
            if (0 == t.code) {
              if (typeof that.getTabBar === 'function' &&
                that.getTabBar()) {
                if (t.data.mch_list.length > 0) {
                  var length = t.data.list.length + t.data.mch_list[0].list.length;
                } else {
                  var length = t.data.list.length
                }
                that.getTabBar().setData({
                  cart_num: length
                })
              }
            }
          }
        });
      },
    })
  },

  show_navs: function () {
    var url = this.currentPage.route;
    if (url.indexOf('pages/index/index') >= 0 ||
      url.indexOf('pages/cat/cat') >= 0 ||
      url.indexOf('pages/cart/cart') >= 0 ||
      url.indexOf('pages/posts/index') >= 0 ||
      url.indexOf('vgoods/edit/index') >= 0 ||
      url.indexOf('pages/user/user') >= 0
    ) {
        return false;
    }

    var t = this;
    var nav = wx.getStorageSync("_navbar");
    if (nav && nav != '' && nav != undefined) {
      this.showUpdate(nav,url)
    } else {
      getApp().request({
        url: getApp().api.default.navbar,
        success: function (e) {
          t.showUpdate(e.data,url)
        }
      });
    }
  },
  showUpdate: function (nav,url) {
    var that = this.currentPage;
    for (var i = 0; i < nav.navs.length; i++) {
      if (nav.navs[i].url == url || nav.navs[i].url.indexOf(url) >= 0 ) {
        if (getApp().globalData.nav_index == i) {
          that.setData({
            selected: getApp().globalData.nav_index,
            is_show_nav: 1,
            is_tabber: 1,
            nav_list: nav
          })
        } else {
          getApp().globalData.nav_index = i;
          that.setData({
            selected: getApp().globalData.nav_index,
            is_show_nav: 1,
            is_tabber: 1,
            nav_list: nav
          })
        }
      }
    }
  },
  switchTab(e) {
    const data = e.currentTarget.dataset
    const url = data.path
    getApp().globalData.nav_index = data.index

    if (url.indexOf('pages/index/index') >= 0 ||
      url.indexOf('pages/cat/cat') >= 0 ||
      url.indexOf('pages/cart/cart') >= 0 ||
      url.indexOf('pages/posts/index') >= 0 ||
      url.indexOf('pages/user/user') >= 0
    ) {
      wx.switchTab({ url })
    } else {
      wx.navigateTo({
        url: url,
      });
    }
  },
  switchTo(e) {
    const data = e.currentTarget.dataset
    const url = data.path
    getApp().globalData.nav_index = data.index
    wx.redirectTo({
      url: url,
    });
  },
  //回到顶部
  goTop: function (e) {  // 一键回到顶部
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },

  get_all_color:function() {
    var t = getApp(),o=this;
    t.request({
      url: t.api.default.navigation_bar_color,
      success: function(e) {
        0 == e.code && (t.hj.setStorageSync("_navigation_bar_color", e.data), o.setNavigationBarColor());
      }
  });
  },
  setNavigationBarColor: function () {
    var that = this.currentPage;
    var cl = wx.getStorageSync('_navigation_bar_color').themeColor;
    var cl_b = !cl || cl == '#ffffff' ? '#ff4544' : cl;
    var color_rgb = this.hexToRgb(cl_b);
    var back_start = 'rgba(' + color_rgb.r + ',' + color_rgb.g + ',' + color_rgb.b + ',.5)'
    var back_end = 'rgba(' + color_rgb.r + ',' + color_rgb.g + ',' + color_rgb.b + ',1)'
    that.setData({
      all_color: cl ? cl : '#ffffff',
      back_start: back_start,
      back_end: back_end
    });
    wx.setNavigationBarColor({
      frontColor: cl != '#ffffff' ? '#ffffff' : '#000000',
      backgroundColor: cl,
      animation: {
        duration: 0,
        timingFunc: 'easeIn'
      }
    })
  },
  hexToRgb: function (hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
      r: parseInt(result[1], 16),
      g: parseInt(result[2], 16),
      b: parseInt(result[3], 16)
    } : null;
  },

};